//
//  BaseCollectionVIew.m
//  HuiWenMovie
//
//  Created by niceDay on 15/7/25.
//  Copyright (c) 2015年 computer. All rights reserved.
//

#import "BaseCollectionVIew.h"
#import "common.h"

@implementation BaseCollectionVIew

- (void)setMovieModalArray:(NSArray *)movieModalArray{
    
    _movieModalArray = movieModalArray;
    [self reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _movieModalArray.count;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    // CGFloat cellWidth = Kwidth*0.75;
    return  UIEdgeInsetsMake(0, (Kwidth- self.itemWidth)/2 , 0, (Kwidth- self.itemWidth)/2);
    
}


- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    
    
    CGFloat x = targetContentOffset->x;
    NSInteger index = x/self.itemWidth;
    
    if (index < 0) {
        index = 0;
    }
    
    else if (index > _movieModalArray.count){
        index = _movieModalArray.count-1;
    }
    self.currentIndex = index;
    targetContentOffset->x = self.itemWidth*index;
    
}

@end
